package com.xiaoke.controller;

import com.xiaoke.domain.ResponseResult;
import com.xiaoke.domain.dto.CreateCategoryDTO;
import com.xiaoke.domain.dto.PagingDTO;
import com.xiaoke.domain.dto.UpdateCategoryDTO;
import com.xiaoke.service.AdminArticleService;
import com.xiaoke.service.AdminCategoryService;
import com.xiaoke.service.CategoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 文章分类表(Category)表后台控制层
 *
 * @author xiaoke
 * @since 2023-04-02 19:35:36
 */
@RestController
@RequestMapping("/admin/category")
public class AdminCategoryController {

    @Resource
    AdminCategoryService adminCategoryService;

    @GetMapping
    public ResponseResult getCategoryList(PagingDTO dto) {
        return adminCategoryService.getCategoryList(dto);
    }

    @GetMapping("/{id}")
    public ResponseResult getCategory(@PathVariable Long id) {
        return adminCategoryService.getCategory(id);
    }

    @PostMapping
    public ResponseResult createCategory(@RequestBody @Validated CreateCategoryDTO dto) {
        return adminCategoryService.CreateCategoryDTO(dto);
    }

    @PutMapping("/{id}")
    public ResponseResult updateCategory(@RequestBody @Validated UpdateCategoryDTO dto, @PathVariable Long id) {
        return adminCategoryService.updateCategory(dto,id);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delCategory(@PathVariable Long id) {
        return adminCategoryService.delCategory(id);
    }

}

